package com.item;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * 演示Collections工具类的使用(添加、排序......)
 */
public class CollectionsDemo {
    public static void main(String[] args) {
        tset0();
        test1();
    }

    private static void tset0() {
        List<String> list = new ArrayList<>();
        Collections.addAll(list, "张三", "李四", "王五", "赵六");
        list.forEach(System.out::println);
        System.out.println("--------------------------");
        Collections.shuffle(list);
        list.forEach(System.out::println);
    }

    public static void test1(){
        List<Integer> list = new ArrayList<>();
        Collections.addAll(list,1,2,3,4,5,6,7,8,9,10);
        Collections.sort(list);
        list.forEach(System.out::println);
        Collections.sort(list, (o1, o2)-> {
            //倒序
            return o2-o1;
        });
        System.out.println("--------------------------");
        list.forEach(System.out::println);

        List<Student> list1 = new ArrayList<>();
        list1.add(new Student("张三", 18));
        list1.add(new Student("李四", 20));
        list1.add(new Student("王五", 19));
        list1.add(new Student("赵六", 21));
        Collections.sort(list1);
        list1.forEach(System.out::println);

    }
}
